<?php
/*
 * @Date: 2020-05-03 22:03:52
 * @名称: 搜索用户信息
 * @版本: 0.01
 * @作者: 初雪桜
 * @邮箱: 202184199@qq.com
 * @最后编辑人: 初雪桜
 * @LastEditTime: 2021-01-29 13:46:18
 * @FilePath: /Site/app/useradmin/controller/SelectController.php
 */

namespace app\useradmin\controller;

use app\BaseController;
use app\useradmin\controller\SelectController\SelectUserInfo\SelectUseInfor;
use think\facade\Db;
use think\facade\View;

class SelectController extends BaseController
{
    public function selectUserInfo()
    {
        $token = cookie("Authorization");;
        $userTokenVerificationParse = ParseUserToken($token, true);
        if ($userTokenVerificationParse['code'] != 200) {
            return json($userTokenVerificationParse);
        }
        $keyWord = input('keyword', " ");
        $search = array(" ", "　", "\n", "\r", "\t");
        $replace = array("", "", "", "", "");
        $keyWord = str_replace($search, $replace, $keyWord);

        $postData['toKen'] = input('post.toKen'); //toKen我自己的
        $postData['bookId'] =  input('post.bookId'); //书籍id
        $postData['time'] = input('post.time'); //时间戳
        $postData['verificationBookId'] = input('post.verificationBookId'); //sha256的书籍id

        $SelectUseInfor = new SelectUseInfor($this->app);
        return $SelectUseInfor->SelectUseInfor($token, $keyWord, $postData);
    }
    public function SelectTags()
    {
        $user_info = config("globalsettings.user_info"); //用户信息

        $keyWord = input('keyword', " ");
        $search = array(" ", "　", "\n", "\r", "\t");
        $replace = array("", "", "", "", "");
        $keyWord_a = str_replace($search, $replace, $keyWord);
        if ($keyWord_a == "") {
            return errorJsonReturn('请填写关键字'); //到这里就是验证错误 验证书籍错误
        } else {
            unset($keyWord_a);
        }
        $postData['toKen'] = input('post.toKen'); //toKen我自己的
        $postData['bookId'] =  input('post.bookId'); //书籍id
        $postData['time'] = input('post.time'); //时间戳
        $postData['verificationBookId'] = input('post.verificationBookId'); //sha256的书籍id
        $comicsTagList = [];
        $TagList = Db::table('tags')
            ->where(
                "tag_name",
                'like',
                "%$keyWord%"
            )
            ->select();
        if (count($TagList) == 0) {

            array_push($comicsTagList, [
                "name" =>  "创建标签:$keyWord -",
                "value" => $keyWord,
            ]);
            return successJsonReturn($comicsTagList);
        }

        foreach ($TagList as $key => $value) {
            array_push($comicsTagList, [
                "name" => "使用标签: $value[tag_name] -",
                "value" => $value["tag_name"],
            ]);
        }
        return successJsonReturn($comicsTagList);
    }
}
